# Comment/uncomment the following line to disable/enable debugging
DEBUG = n


# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DSCULL_DEBUG -DALBERO_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

EXTRA_CFLAGS += $(DEBFLAGS)
EXTRA_CFLAGS += -I$(LDDINC)
EXTRA_CFLAGS += -D ALBERO_KERNEL_MODE

ifneq ($(KERNELRELEASE),)
# call from kernel build system

scull-objs := main.o pipe.o access.o albero.o

obj-m	:= scull.o

else

KERNELDIR ?= /lib/modules/$(shell uname -r)/build
#KERNELDIR ?= /home/pie/Documents/trento/uni/opsys/linux/linux-2.6.31.12
PWD       := $(shell pwd)

modules:
#	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=/home/pie/Documents/trento/uni/opsys/linux/build-linux-2.6.31.12/include modules
	$(MAKE) -C $(KERNELDIR) M=$(PWD) LDDINC=$(PWD)/../include modules

endif



clean:
	rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

depend .depend dep:
	$(CC) $(CFLAGS) -M *.c > .depend

test.o: test.c
	$(CC) -Wall -c -I/lib/modules/2.6.31.12/build/include/ $(DEBFLAGS) -o test.o test.c

albero_user.o: albero.c
	$(CC) -Wall -c  $(DEBFLAGS) -o albero_user.o albero.c

test : test.o albero_user.o
	$(CC) -lpthread -o test test.o albero_user.o

ifeq (.depend,$(wildcard .depend))
include .depend
endif
